﻿using System;
using System.Net;
using System.Linq;
using Enyim.Caching;
using System.Web.Mvc;
using SilenthinkContract;
using SilenthinkContract.Domain;
using System.Collections.Generic;
using SilenthinkContract.Component;

namespace Web.Manage.Controllers
{
    public class LogController : BaseController
    {
        public LogController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient) : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        public void Index()
        {

        }

        public ActionResult AppErrors(int page = 1, int size = 20, byte level = 0, string machineIp = null, string server = null, string userName = null, string clientIp = null)
        {
            ViewBag.Level = level;
            ViewBag.MachineIp = machineIp;
            ViewBag.Server = server;
            ViewBag.UserName = userName;
            ViewBag.ClientIp = clientIp;

            var model = LogService.GetPagedAppError(page, size, level, machineIp, userName, clientIp).ToPagedList(page, size);
            return PartialView(model);
        }

        public ActionResult AppError(int param = 0)
        {
            var model = LogService.GetAppError(param);
           
            return PartialView(model);
        }

        public ActionResult CleanAppErrors()
        {
            var result =LogService.TruncateAppError();
            return result ? Json(HttpStatusCode.OK, "清除成功", false, "/log/apperrors") : Json(HttpStatusCode.BadRequest, "清除失败");
        }
    }
}
